package com.jason.concurrent.async;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Author  yslai
 * @Date  2022/9/20 15:00
 * @Description 异步有没有返回值的测试demo
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(
                ()->{
                    System.out.println(Thread.currentThread().getName());
                    return 1023;
                }
        );
        Integer integer = future.get();
        System.out.println(integer);

        //没有返回值
        CompletableFuture<Void> f2 = CompletableFuture.runAsync(
                ()->{
                    System.out.println(Thread.currentThread().getName());
//                    return 1023;
                }
        );
//        Integer integer = future.get();
        f2.get();
        System.out.println();
    }
}
